package com.designpattern.singleton;

/**
 * @author liyanhao
 * @Date 2023-02-06 20:42
 * 懒汉式 线程安全 双重检查锁 推荐使用
 */
public class SingletonTest04 {
    public static void main(String[] args) {

    }
}

class Singleton04 {
    private static Singleton04 instance;

    private Singleton04() {
    }

    public static Singleton04 getInstance() {
        if (instance == null) {
            synchronized (instance){
                if (instance == null) {
                    return new Singleton04();
                }
            }
        }
        return instance;
    }
}
